package com.yang.core.client;

import com.yang.core.config.RestClientConfig;
import com.yang.core.model.RequestContext;
import com.yang.core.model.RawResponse;
import com.yang.core.api.RestClientException;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * 请求执行器
 */
@Slf4j
public class RequestExecutor {

    private final HttpClient httpClient;
    private final RestClientConfig config;

    public RequestExecutor(HttpClient httpClient, RestClientConfig config) {
        this.httpClient = httpClient;
        this.config = config;
    }

    /**
     * 执行请求
     */
    public RawResponse execute(RequestContext requestContext) {
        try {
            // 这里应该是实际的HTTP请求执行逻辑
            // 为了简化，我们返回一个模拟的响应
            log.debug("执行请求: {} {}", requestContext.getMethod(), requestContext.getUrl());

            return RawResponse.builder()
                    .statusCode(200)
                    .body("{\"message\": \"Success\"}")
                    .headers(Map.of("Content-Type", "application/json"))
                    .message("OK")
                    .build();

        } catch (Exception e) {
            log.error("请求执行失败", e);
            throw new RestClientException("请求执行失败", e);
        }
    }
}